<?php

namespace app\controller;

use think\facade\Db;
use think\facade\Request;
use app\BaseController;
use app\ResourceModel;

class ResourceReportController extends BaseController
{
    //获取举报列表
    public function getReportList(Request $request)
    {
        $param = $request::param();
        $where = [];
        if (!empty($param['report_title'])) {
            $where['report_title'] = $param['report_title'];
        }
        $list = Db::table('shenbei_site_online_reporting')
            ->where('del_flag', 0)
            ->where($where)
            ->select()->toArray();
        return $this->returnJson(1001, '返回成功', ['list' => $list]);
    }
   //获取举报标题列表
    public function getReportTitleList(Request $request)
    {
        $param = $request::param();
        $list = Db::table('shenbei_site_online_reporting')
            ->where('del_flag', 0)
            ->field('report_title')
            ->select()->toArray();
        return $this->returnJson(1001, '返回成功', ['list' => $list]);

    }
    //通过id编辑列表
    public function getReportById(Request $request)
    {
        $param = $request::param();

        $list = Db::table('shenbei_site_online_reporting')
            ->where('del_flag', 0)
            ->where('id', $param['id'])
            ->select()->toArray();
        return $this->returnJson(1001, '返回成功', ['list' => $list]);

    }
    //编辑举报信息
    public function editReport(Request $request)
    {
        $param = $request::param();
        $data['report_title']=$param['report_title'];
        $data['report_people_name']=$param['report_people_name'];
        $data['phone']=$param['phone'];
        $data['be_complain_name']=$param['be_complain_name'];
        $data['report_content']=$param['report_content'];
        $ret = Db::table('shenbei_site_online_reporting')->where('id', $param['id'])->update($data);
        if ($ret != false) {
            return $this->returnJson(1001, '修改成功', $param);
        } else {
            return $this->returnJson(1002, '修改失败');
        }
    }
    //删除单条
    public function deleteReport(Request $request)
    {
        $param = $request::param();
        $result = Db::table('shenbei_site_online_reporting')
            ->where('id', $param['id'])
            ->update(['del_flag' => 1]);
        if ($result != false) {
            return $this->returnJson(1001, '删除成功');
        } else {
            return $this->returnJson(1002, '删除失败');
        }
    }
    //批量删除
    public function deleteReportStrips(Request $request)
    {
        $param = $request::param();
        $result = Db::table('shenbei_site_online_reporting')
            ->whereIn('id', json_decode($param['ids']))
            ->update(['del_flag' => 1]);
        if ($result != false) {
            return $this->returnJson(1001, '删除成功');
        } else {
            return $this->returnJson(1002, '删除失败');
        }
    }
}
